<template>
<div>
  <el-dialog title="提交审批结果"
    :visible.sync="visible"
    :close-on-click-modal="false"
    class="edit-form"
    @close="$emit('update:approvalOtherSubmitFormShow', false)"
  >
   <el-form :model="editForm" label-width="180px" ref="editForm">
    <el-tag>基本信息</el-tag>
	  <el-form-item label="序号">
	    <el-input v-model="editForm.squence" :disabled="true"></el-input>
	  </el-form-item>
		<el-form-item label="申请单号">
		  <el-input v-model="editForm.work_order_code" :disabled="true"></el-input>
		</el-form-item>
	  <el-form-item label="申请单位名称">
		  <el-input v-model="editForm.applicant_name" placeholder="申请单位名称" :disabled="true"></el-input>
		</el-form-item>
		<el-form-item label="申请单位地址">
		  <el-input v-model="editForm.applicant_addres" placeholder="申请单位地址" :disabled="true"></el-input>
		</el-form-item>
	  <el-form-item label="单位联系人" prop="unit_contact">
		<el-input v-model="editForm.unit_contact" :disabled="true"></el-input>
	  </el-form-item>
	  <el-form-item label="联系电话" prop="telephone">
		<el-input v-model="editForm.telephone" :disabled="true"></el-input>
	  </el-form-item>
	  <el-form-item label="E-mail" prop="E_mail">
		<el-input v-model="editForm.E_mail" :disabled="true"></el-input>
	  </el-form-item>
	  <el-form-item label="业务系统名称" prop="business_system_name">
		<el-input v-model="editForm.business_system_name" :disabled="true"></el-input>
	  </el-form-item>
	  <el-form-item label="接口人/电话" prop="interface_tel">
		<el-input v-model="editForm.interface_tel" :disabled="true"></el-input>
	  </el-form-item>

	  <el-tag>风险操作</el-tag>
	  <el-form-item label="风险操作内容" prop="risk_operation">
			<el-input v-model="editForm.risk_operation" :disabled="true"></el-input>
			<a :href="'http://218.63.75.44:8887/preview/' + editForm.file_path " target="view_window">查看附件</a>
	  </el-form-item>
	
		
		<el-tag>处理意见</el-tag>			
		<el-form-item v-if="editForm.current_link=='待审批'" label="审批意见" prop="approve">
			<el-select v-model="editForm.approve" placeholder="请选择审批意见">
				<el-option label="同意" value="同意"></el-option>
				<el-option label="不同意" value="不同意"></el-option>
			</el-select>
		</el-form-item>
		<el-form-item v-else-if="editForm.current_link=='待执行'" label="执行情况" prop="approve">
			<el-select v-model="editForm.approve" placeholder="请选择执行情况">
				<el-option label="执行完成" value="执行完成"></el-option>
				<el-option label="未执行" value="未执行"></el-option>
			</el-select>
		</el-form-item>
		<el-form-item v-else="editForm.current_link=='待验收'" label="验收意见" prop="approve">
			<el-select v-model="editForm.approve" placeholder="请选择验收意见">
				<el-option label="同意验收" value="同意验收"></el-option>
				<el-option label="不同意验收" value="不同意验收"></el-option>
			</el-select>
		</el-form-item> 		
   </el-form>
   <div slot="footer" class="dialog-footer">
    <el-button @click.native="handleCancel()">取消</el-button>
    <el-button v-if="editForm.current_link=='待审批'" type="primary" @click.native="handleApproval()">审批同意</el-button>
    <el-button v-else-if="editForm.current_link=='待执行'" type="primary" @click.native="handleOpen()">执行完成</el-button>
    <el-button v-else="editForm.current_link=='待验收'" type="primary" @click.native="handleCheck()">同意验收</el-button>
   </div>
  </el-dialog>
</div>
</template>

<script>
import axios from 'axios'
export default {
  name:'ApprovalOtherSubmitForm',
  data(){
	  
    return{
	  approve:'',
      visible:this.approvalOtherSubmitFormShow,
      editForm:this.approvalOtherSubmitForm
    }
  },
 
  watch: {
    visible(){
      this.visible = this.approvalOtherSubmitFormShow;
    }
  },
  props: {
    approvalOtherSubmitFormShow: {
      type: Boolean,
      default: false
    },
    approvalOtherSubmitForm: {
      type: Object,
      default:{}
    }
  },
  mounted(){
    console.log(this.editForm)
  },
  methods: {
    handleCancel(){
      this.$emit('update:approvalOtherSubmitFormShow', false)
    },
    handleApproval(){
			let name = localStorage.getItem('cur_username')
		  axios
        .get('/api/approval_other/',{
					params:{		
						work_order_code:this.editForm.work_order_code,
						process:this.editForm.process,
						name:name,
					},
				})
        .then((res) =>{
					if(res.data.code==200){
						this.$message({
							message: '审批成功！',
							type: 'success'
						})
					}else if(res.data.code==404){
						this.$message({
							message: '未找到记录！',
							type: 'warning'
						})
					}else if(res.data.code==500){
						this.$message({
							message: '数据库错误！',
							type: 'error'
						})
					}else{
						this.$message({
							message: '未知错误！',
							type: 'error'
						})
					}
        })
        .catch((error)=>{
          console.log(error);
        })
			//触发父组件的getData方法,更新表格数据
			this.$emit('getData')
      //更新父组件的表单显示参数，隐藏表单
      this.$emit('update:approvalOtherSubmitFormShow', false)
    },
		handleOpen(){
			let name = localStorage.getItem('cur_username')
		  axios
        .get('/api/open_other/',{
					params:{
						work_order_code:this.editForm.work_order_code,
						process:this.editForm.process,
						name:name,
					},
				})
        .then((res) =>{
					if(res.data.code==200){
						this.$message({
							message: '执行成功！',
							type: 'success'
						})
					}else if(res.data.code==404){
						this.$message({
							message: '未找到记录！',
							type: 'warning'
						})
					}else if(res.data.code==500){
						this.$message({
							message: '数据库错误！',
							type: 'error'
						})
					}else{
						this.$message({
							message: '未知错误！',
							type: 'error'
						})
					}
        })
		    .catch((error)=>{
		      console.log(error);
		    })
			//触发父组件的getData方法,更新表格数据
			this.$emit('getData')
		  //更新父组件的表单显示参数，隐藏表单
		  this.$emit('update:approvalOtherSubmitFormShow', false)
		},
		handleCheck(){
			let name = localStorage.getItem('cur_username')
		  axios
        .get('/api/check_other/',{
					params:{
						work_order_code:this.editForm.work_order_code,
						process:this.editForm.process,
						name:name,
					},
				})
        .then((res) =>{
					if(res.data.code==200){
						this.$message({
							message: '验收成功！',
							type: 'success'
						})
					}else if(res.data.code==404){
						this.$message({
							message: '未找到记录！',
							type: 'warning'
						})
					}else if(res.data.code==500){
						this.$message({
							message: '数据库错误！',
							type: 'error'
						})
					}else{
						this.$message({
							message: '未知错误！',
							type: 'error'
						})
					}
        })
		    .catch((error)=>{
		      console.log(error);
		    })
			//触发父组件的getData方法,更新表格数据
			this.$emit('getData')
		  //更新父组件的表单显示参数，隐藏表单
		  this.$emit('update:approvalOtherSubmitFormShow', false)
		},
  },
}
</script>

<style>
</style>

